package com.xq;

import com.xq.props.*;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.List;

/**
 * @description:
 * @author: 软妹倩哟
 * @date: Created in 2020/6/6 16:54
 * @version: v1.0
 * @modified By:
 */
public class Hunter {
    String name;
    int maxLife;
    int curLife;
    boolean isLive = true;
    String weapon;
    int attack;
    int stcATK;
    int defend;
    int level;
    int exp;
    int agile;
    int hideRate;
    Room currentRoom;
    private HashMap<String, Props> bag = new HashMap<String, Props>();
    private Props currentWeapon = null;

    private static Hunter hunter = new Hunter("name", 100, 20, 20, 1, 0, 10, 10);

    public Hunter(String name, int maxLife, int attack, int defend, int level, int exp, int agile, int hideRate) {
        this.name = name;
        this.maxLife = maxLife;
        this.curLife = maxLife;
        this.attack = attack;
        this.stcATK = attack;
        this.defend = defend;
        this.level = level;
        this.exp = exp;
        this.agile = agile;
        this.hideRate = hideRate;
    }
    //    private Hunter(String name,String weapon){
//        this.name = name;
//        this.weapon = weapon;
//        maxLife = 100;
//        curLife = maxLife;
//        isLive = true;
//        attack = 25;
//        stcATK = attack;
//        defend = 8;
//        level = 1;
//        exp = 0;
//        agile = 35;
//        hideRate = 60;
//    }


    public void setName(String name) {
        this.name = name;
    }

    public int getMaxLife() {
        return maxLife;
    }

    public void setMaxLife(int maxLife) {
        this.maxLife = maxLife;
    }

    public int getCurLife() {
        return curLife;
    }

    public void setCurLife(int curLife) {
        this.curLife = curLife;
    }

    public int getAttack() {
        return attack;
    }

    public void setAttack(int attack) {
        this.attack = attack;
    }

    public int getStcATK() {
        return stcATK;
    }

    public static Hunter getHunter() {
        return hunter;
    }

    public Room getCurrentRoom() {
        return currentRoom;
    }

    public void setCurrentRoom(Room room) {
        currentRoom = room;
    }

    public String getName() {
        return name;
    }

    public int getDefend() {
        return defend;
    }

    public void getProps(String name, Props props) {
        bag.put(name, props);
        System.out.println("你获得了" + name);
    }

    public void showHunter() {
        System.out.println("名字：" + getName());
        System.out.println("等级：" + level);
        System.out.println("血量：" + getCurLife());
        System.out.println("攻击力：" + getAttack());
        System.out.println("防御力：" + getDefend());
    }

    public void showBag() {
        List<Props> valueList = new ArrayList<Props>(bag.values());
        for (Props props : valueList) {
            System.out.print("ID；" + props.getId());
            System.out.print("\t物品名称：" + props.getName() + "\t\t");
            System.out.println(props.toString() + props.getEffect());
        }
    }

    public void useProps(String word) {
        int flag = 0;
        int propsID = Integer.parseInt(word);
        List<Props> valueList = new ArrayList<Props>(bag.values());
        for (Props props : valueList) {
            if (word.equals(props.getId())) {
                if (101 <= propsID && propsID <= 103) {
                    if (currentWeapon != null) {
                        getProps(currentWeapon.getName(), currentWeapon);
                    }
                    currentWeapon = props;
                    currentWeapon.useProps(this);
                    flag++;
                    bag.remove(currentWeapon.getName());   //通过键删除哈希表的键值对
                    System.out.println("你的" + currentWeapon.toString() + currentWeapon.getEffect() + "，当前攻击力为" + getAttack());
                } else if (110 <= propsID && propsID <= 111) {
                    props.useProps(this);
                    flag++;
                    bag.remove(props.getName());
                    System.out.println("你的" + props.toString() + props.getEffect() + "，当前生命值为" + getCurLife());
                }
            }
        }
        if (flag == 0) {
            System.out.println("当前背包尚无此物品");
        }
    }

    public void fight(Monster monster) {     //战斗
        if (monster.isLive) {
            if (isLive) {
                System.out.println("--------->" + name + "无情的拿起" + currentWeapon.getName() + "杀向" + monster.type + "<----------------");
                monster.injured(this);
            } else {
                System.out.println("--------->" + "我们的主角" + name + "已经牺牲了" + "<----------------");
            }
        } else {
            System.out.println("拜托啊！这个丧尸已经被你打死啦！");
        }
    }

    public void injured(Monster monster) {   //掉血
        //增加躲避的判断
        if (monster.type == "吸血鬼") {
            if (GameUtil.hidden(this.agile, this.hideRate)) {
                System.out.println("--------" + name + ":小样，打不到我");
                show();
                fight(monster);
                return;
            }
            System.out.println("--------->" + name + ":疼死了，打死你个龟孙" + "<---------");
            int lostLife = GameUtil.calLostLife(monster.attack, this.defend);
            curLife -= lostLife;
            if (curLife < 0) {
                curLife = 0;
                died();
                return;
            }
            monster.curLife += this.curLife / 10;
            show();
            fight(monster);
        } else {
            if (GameUtil.hidden(this.agile, this.hideRate)) {
                System.out.println("--------" + name + ":小样，打不到我");
                show();
                fight(monster);
                return;
            }
            System.out.println("--------->" + name + ":疼死了，打死你个龟孙" + "<---------");
            int lostLife = GameUtil.calLostLife(monster.attack, this.defend);
            curLife -= lostLife;
            if (curLife < 0) {
                curLife = 0;
                died();
                return;
            }
            show();
            fight(monster);
        }
    }

    public void expAdd(Monster monster) {
        this.exp += monster.maxLife;
        int needExp = 0;
        for (int i = 1; i <= level; i++) {
            needExp += i * 50;
        }
        if (exp >= needExp) {
            upgrade();
        }

    }

    public void upgrade() {
        attack += 4;
        defend += 3;
        maxLife += 20;
        curLife += maxLife;
        level++;
        System.out.println("--------------------------分割线-------------------------");
        System.out.println("系统提示：升级啦，目前等级" + level + "血量" + curLife + "攻击力" + attack + "防御力" + defend);
    }

    public void died() {
        System.out.println("**********" + name + "被丧尸咬死了" + "**********");
        isLive = false;
        show();
    }

    public void show() {
        System.out.println("---------->" + name + "  " + "生命值:" + curLife + "  " +
                "生命状态" + isLive + "   " + "等级" + level + "   "
                + "<-------------");
    }


}
